import os, time

fontfile = 'msyh.ttf'
glslfile = '/home/mc/taozhuo/ffmpeg-gl-transition/gl-transitions/transitions/DreamyZoom.glsl'
sname = 'qianshou'
fontsize = 100
input = ''
drawFilter = ''
os.system('rm  text.mp4')
input = f' -i t.mp4 '
showtext = '淘卓科技'   


showtexts = [
    '我的表演',
    '我是新郎',
    '李雷雷',
    '一个',
    '英俊',
    '潇洒'
    '玉树临风',
    '学富五车',
    '才高八斗',
    '人见人爱',
    '花见花开',
    '车见车爆胎'
]

input = f'  -t 2 -loop 1  -i {sname}0.jpg  -t 2   -f lavfi -i color=Black:820x546   '
# input = f'  -t 2 -loop 1  -i {sname}0.jpg   -t 2 -loop 1  -i {sname}1.jpg   '

drawFilter = f'[1:v]drawtext=fontfile={fontfile}:text=\'{showtexts[0]}\':\
fontcolor=white:fontsize={fontsize}:x=(w-tw)/2:y=(h/2)-th,format=yuv420p [tmp]'

gltransition =  f'[0:v][tmp]gltransition=offset=0.5:duration=1.5:source={glslfile}[v1];[v1]scale=820x546 [v2]'
wzoom = ''
# wzoom = f'; [v2]zoompan=z=\'zoom+0.002\':d=25*4  [v3]'
allFilter = f'{drawFilter};{gltransition}{wzoom}'
ffmpegcmd = f'ffmpeg  {input}  -filter_complex  "{allFilter}" -map "[v2]"  -y  text.mp4  '


# drawFilter= f'drawtext=fontfile=msyh.ttf:fontcolor=white:text=\'{showtext}\'\
# :fontsize={fontsize}\
# :x=(w-text_w)/2:y=(h-text_h)/2'
# ffmpegcmd = f'ffmpeg  {input}  -filter_complex  "{drawFilter}" -y text.mp4  '

print('ffmpegcmd is ', ffmpegcmd)
os.system(ffmpegcmd)   
os.system('ffplay text.mp4')   













# https://github.com/Zulko/moviepy
# https://el-tramo.be/blog/ken-burns-ffmpeg/    Ken Burns Effect Slideshows with FFMPeg
# https://github.com/tanersener/ffmpeg-video-slideshow-scripts
# https://superuser.com/questions/874598/creating-video-containing-animated-text-using-ffmpeg-alone
# ffmpeg -y -ss 00:00:30 -i ../toystory.mp4 -t 8 -c copy t.mp4
# ffplay -i qianshou0.jpg   -vf "crop=100:100;zoompan=z='zoom+0.002':d=25*4" 

#1 
# drawFilter= f'drawtext=fontfile={fontfile}:fontsize={fontsize}:text=\'Test Text\':\
# x=100: y=50 : fontcolor=yellow@0.2: box=1: boxcolor=red@0.2'

# UTF-8 encoded characters
# https://blog.csdn.net/DeliaPu/article/details/76162489

# http://www.ffmpeg.org/ffmpeg-utils.html
# gt(x, y) Return 1 if x is greater than y, 0 otherwise.
# gte(x, y) Return 1 if x is greater than or equal to y, 0 otherwise.
# PI area of the unit disc, approximately 3.14
# E exp(1) (Euler’s number), approximately 2.718
# PHI golden ratio (1+sqrt(5))/2, approximately 1.618
# lt(x, y) Return 1 if x is lesser than y, 0 otherwise.
# lte(x, y) Return 1 if x is lesser than or equal to y, 0 otherwise.
# max(x, y) Return the maximum between x and y.

# between(x, min, max) Return 1 if x is greater than or equal to min and lesser than or equal to max, 0 otherwise.




